//
//  Status.swift
//  weibo
//
//  Created by cmh on 15/9/6.
//  Copyright © 2015年 cmh. All rights reserved.
//

import UIKit

// 微博模型
class Status: NSObject {
    
    // 创建时间
    var created_at: String?
    /// 微博ID
    var id: Int = 0
    /// 微博信息内容
    var text: String?
    /// 微博来源
    var source: String?
    /// 用户模型 － 如果直接使用 KVC，会变成字典
    var user: User?
    /// 配图URL字符串的数组
    var pic_urls: [[String: String]]?
    
    // 转发微博标志
    var retweeted_status: Status?
    
    init(dict: [String: AnyObject]) {
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    // 重写这个方法是为了让user模型也初始化
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
        
            user = User(dict: value as! [String : AnyObject])
            
            return
            
        }
        
        if key == "retweeted_status" {
            retweeted_status = Status(dict: value as! [String: AnyObject])
            
            return
        }
        
        super.setValue(value, forKey: key)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    }
    
    // 重写description为了调试
    override var description: String {
    
        let keys = ["created_at", "id", "text", "source", "user", "pic_urls"]
        
        return dictionaryWithValuesForKeys(keys).description
        
        
    }

}
